﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.BasicsDatum;
using SmartWMS.Server.BasicsDatumServer.UnitServer;
using SmartWMS.Server.BasicsDatumServer.UnitServer.Dto;
using Yitter.IdGenerator;

namespace SmartWMS.API.Controllers.BasicsDatumMange
{
    /// <summary>
    /// 单位数据管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "BasicsDatum")]
    public class UnitsController : ControllerBase
    {
        private readonly IUnitServers _unitServers;

        public UnitsController(IUnitServers unitServers)
        {
            _unitServers = unitServers;
        }


        /// <summary>
        /// 单位列表（查询）
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<List<UnitDtoPes>>> GetUnitAsync(UnitPageDto dto)
        {
            try
            {
                var list = await _unitServers.GetUnitAsync(dto);
                return list;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 添加单位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddUnitAsync(UnitDtoPes dto)
        {
            try
            {
                //dto.UnitCode=YitIdHelper.NextId().ToString();
                var result= await _unitServers.AddUnitAsync(dto);
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 删除单位数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DelUnit(UnitDtoPes dto)
        {
            try
            {
                var result = await _unitServers.DelUnit(dto);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 批量删除方法
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DeletesUnit(UnitDtoPes dto)
        {
            try
             {
               var result= await _unitServers.DeletesUnit(dto);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 反填单位数据方法
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<UnitDtoPes>> ReckUnit(UnitDtoPes dto)
        {
            try
            {
               var list= await _unitServers.ReckUnit(dto);
                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改单位数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> UpdateUnitAsync(UnitDtoPes dto)
        {
            try
            {
               var result= await _unitServers.UpdateUnitAsync(dto);
                return result;
            }
            catch (Exception)
            {
                throw;
            }
        }


    }
}
